package com.itboye.lottery.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.bylibrary.widget.glide.GlideUtil;
import com.itboye.lottery.R;
import com.itboye.lottery.bean.BetBean;

import java.util.ArrayList;

/**
 * Created by wu on 2018/1/9.
 */

public class ZhuiHaoManageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Activity activity;
    private Context context;
    ArrayList<BetBean> classEntityArrayList = new ArrayList<>();

    public ZhuiHaoManageAdapter(Activity activity, ArrayList<BetBean> classEntityArrayList) {
        this.activity = activity;
        this.classEntityArrayList = classEntityArrayList;
    }

    public OnItemClickListener itemClickListener;

    public void setOnItemClickListener(ZhuiHaoManageAdapter.OnItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }


    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        return new ViewHolderFind(LayoutInflater.from(context).inflate(R.layout.item_zhuihao, parent, false));
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        BetBean betBean = classEntityArrayList.get(position);
        ViewHolderFind viewHolderFind = (ViewHolderFind) holder;
        viewHolderFind.item_zhuihao_typename.setText(betBean.getName());
        GlideUtil.display(context, betBean.getImg(), viewHolderFind.item_zhuihao_icon);
        viewHolderFind.item_zhuihao_tv_1.setText(String.format("剩余%1d期/共%2d期", betBean.getUse_number(), betBean.getPush_number()));
        viewHolderFind.item_zhuihao_tv_2.setText(betBean.getAdd_time());
        viewHolderFind.item_zhuihao_tv_3.setText(betBean.getAmount() + "元");
        viewHolderFind.item_zhuihao_tv_4.setText(betBean.getIs_rand() == 0 ? "固定追号" : "随机追号");
    }

    @Override
    public int getItemCount() {
        return classEntityArrayList == null ? 0 : classEntityArrayList.size();
    }

    public class ViewHolderFind extends RecyclerView.ViewHolder implements View.OnClickListener {
        public ImageView item_zhuihao_icon;
        public TextView item_zhuihao_typename;
        public TextView item_zhuihao_tv_1;
        public TextView item_zhuihao_tv_2;
        public TextView item_zhuihao_tv_3;
        public TextView item_zhuihao_tv_4;

        public ViewHolderFind(View itemView) {
            super(itemView);
            item_zhuihao_icon = itemView.findViewById(R.id.item_zhuihao_icon);
            item_zhuihao_typename = itemView.findViewById(R.id.item_zhuihao_typename);
            item_zhuihao_tv_1 = itemView.findViewById(R.id.item_zhuihao_tv_1);
            item_zhuihao_tv_2 = itemView.findViewById(R.id.item_zhuihao_tv_2);
            item_zhuihao_tv_3 = itemView.findViewById(R.id.item_zhuihao_tv_3);
            item_zhuihao_tv_4 = itemView.findViewById(R.id.item_zhuihao_tv_4);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (itemClickListener != null) {
                itemClickListener.onItemClick(v, getAdapterPosition());
            }
        }
    }

}
